package com.cloudlibrary.service.impl;

import com.cloudlibrary.domain.Record;
import com.cloudlibrary.domain.User;
import com.cloudlibrary.entity.PageResult;
import com.cloudlibrary.mapper.RecordMapper;
import com.cloudlibrary.service.RecordService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
* @author 30590
* @description 针对表【record】的数据库操作Service实现
* @createDate 2024-12-18 18:15:17
*/
@Service
public class  RecordServiceImpl implements RecordService {
    @Autowired
    private RecordMapper recordMapper;
    @Override
    public Integer addRecord(Record record) {
        return recordMapper.addRecord(record);
    }
    @Override
    public PageResult searchRecords(Record record, User user,Integer pageNum,Integer pageSize){
        PageHelper.startPage(pageNum,pageSize);
        if (!"ADMIN".equals(user.getRole())){
            record.setBorrower(user.getName());
        }
        Page<Record> page = recordMapper.searchRecords(record);
        return new PageResult(page.getTotal(),page.getResult());
    }
}